namespace SPECTRE_VARIANT1 {
	struct array {
		unsigned long length;
		unsigned char data[];
	};

	struct array* createArrayOfSize(unsigned int size);

void vulnerable_pattern(unsigned long offset)
{
	struct array* arr1 = createArrayOfSize(5);
	struct array* arr2 = createArrayOfSize(0x500);
	unsigned char secret_value;

	if (offset < arr1->length) {                                /* untrusted data controls the branch */
		secret_value = arr1->data[offset];                      /* out of boundary read in a mispredicted speculative execution */

		unsigned char value2 = arr2->data[secret_value * 256];  /* arr2->data[secret_value * 256] will be loaded to the CPU cache */
                                                                  /* resulting in a measurable side effect */
          /* some more code */
	}
	else {
		          /* code for the else branch */
	}
}


struct array {
	unsigned long length;
	unsigned char data[];
};

struct array* createArrayOfSize(unsigned int size);

void vulnerable_pattern(unsigned long offset)
{
	struct array* arr1 = createArrayOfSize(5);                  /* small array */
	struct array* arr2 = createArrayOfSize(0x500);              /* a large array */
	unsigned char secret_value;

	if (offset < arr1->length) {                                /* untrusted data controls the branch */
		_mm_lfence();                                           /* serialization intrinsic that stops speculative execution */
		secret_value = arr1->data[offset];                      /* no vulnerability exists so no defect is reported */

		unsigned char value2 = arr2->data[secret_value * 256];

		          /* some more code */
	}
	else {
		          /* code for the else branch */
	}
}
}}